<template>
  <div class="page-header-index-wide page-header-wrapper-grid-content-main">
    <a-row :gutter="24">
      <a-col :md="24" :lg="7">
        <a-card :bordered="false">
          <div class="account-center-avatarHolder">
            <div class="avatar">
              <img :src="avatar()">
            </div>
            <div class="username">{{ nickname() }}</div>
            <div class="bio">{{ $t('accountIndex.hnbcyrnd') }}</div>
          </div>
          <div class="account-center-detail">
            <p>
              <i class="title"></i>$t('accountIndex.zszq')
            </p>
            <p>
              <i class="group"></i>{{ $t('accountIndex.jcjs') }}
            </p>
            <p>
              <i class="address"></i>
              <span>{{ $t('accountIndex.jss') }}</span>
              <span>{{ $t('accountIndex.njs') }}</span>
            </p>
          </div>
        </a-card>
      </a-col>
      <a-col :md="24" :lg="17">
        <a-card
          style="width:100%"
          :bordered="false"
          :tabList="tabListNoTitle"
          :activeTabKey="noTitleKey"
          @tabChange="key => handleTabChange(key, 'noTitleKey')"
        >
          <a-form @submit="handleSubmit" :form="form">
            <a-form-item
              label="$t('accountIndex.jdmm')"
              :labelCol="{lg: {span: 7}, sm: {span: 7}}"
              :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
              <a-input
                type="password"
                v-decorator="[
            'password1',
            {rules: [{ required: true, message: '{{ $t('accountIndex.qsrmm') }}' }]}
          ]"
                name="password1"
                placeholder="$t('accountIndex.qsrysmm')" />
            </a-form-item>
            <a-form-item
              label="$t('accountIndex.xdmm')"
              :labelCol="{lg: {span: 7}, sm: {span: 7}}"
              :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
              <a-input
                type="password"
                v-decorator="[
            'password2',
            {rules: [{ required: true, message: '{{ $t('accountIndex.qsrmm') }}' }]}
          ]"
                name="password2"
                placeholder="$t('accountIndex.qsrxdmm')" />
            </a-form-item>
            <a-form-item
              :wrapperCol="{ span: 12, offset:2 }"
              style="text-align: center"
            >
              <a-button :loading="loading_form" htmlType="submit" type="primary">{{ $t('accountIndex.tj') }}</a-button>
            </a-form-item>
          </a-form>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import { PageView, RouteView } from '@/layouts'
import { AppPage, ArticlePage, ProjectPage } from './page'

import { mapGetters } from 'vuex'

export default {
  components: {
    RouteView,
    PageView,
    AppPage,
    ArticlePage,
    ProjectPage
  },
  data () {
    return {
      tags: [this.$t('accountIndex.hyxfd'), this.$t('accountIndex.zzsj'), '辣~', this.$t('accountIndex.dct'), this.$t('accountIndex.cmz'), this.$t('accountIndex.hnbc')],

      tagInputVisible: false,
      tagInputValue: '',

      teams: [],
      teamSpinning: true,

      tabListNoTitle: [
        {
          key: 'app',
          tab: this.$t('accountIndex.xgmm')
        }
      ],
      noTitleKey: 'app',
      form: this.$form.createForm(this),
      loading_form: false
    }
  },
  mounted () {
  },
  methods: {
    ...mapGetters(['nickname', 'avatar']),

    getTeams () {
      this.$http.get('/workplace/teams').then(res => {
        this.teams = res.result
        this.teamSpinning = false
      })
    },

    handleTabChange (key, type) {
      this[type] = key
    },

    handleTagClose (removeTag) {
      const tags = this.tags.filter(tag => tag !== removeTag)
      this.tags = tags
    },

    showTagInput () {
      this.tagInputVisible = true
      this.$nextTick(() => {
        this.$refs.tagInput.focus()
      })
    },

    handleInputChange (e) {
      this.tagInputValue = e.target.value
    },

    handleSubmit (e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          // eslint-disable-next-line no-console
          console.log('Received values of form: ', values)
          this.loading_form = true
          this.$http.post('/user/change_pwd', this.$qs.stringify(values)).then(res => {
            JSON.stringify()
            if (res.code === 0) {
              this.$notification.success({
                message: this.$t('accountIndex.cg'),
                description: res.msg
              })
            } else {
              this.$notification.error({
                message: this.$t('accountIndex.sb'),
                description: res.msg
              })
            }
          }).catch(err => {
            this.$notification.error({
              message: this.$t('accountIndex.sb'),
              description: err.message
            })
          }).then(() => {
            this.loading_form = false
          })
        }
      })
    },
    handleTagInputConfirm () {
      const inputValue = this.tagInputValue
      let tags = this.tags
      if (inputValue && !tags.includes(inputValue)) {
        tags = [...tags, inputValue]
      }

      Object.assign(this, {
        tags,
        tagInputVisible: false,
        tagInputValue: ''
      })
    }
  }
}
</script>

<style lang="less" scoped>
.page-header-wrapper-grid-content-main {
  width: 100%;
  height: 100%;
  min-height: 100%;
  transition: 0.3s;

  .account-center-avatarHolder {
    text-align: center;
    margin-bottom: 24px;

    & > .avatar {
      margin: 0 auto;
      width: 104px;
      height: 104px;
      margin-bottom: 20px;
      border-radius: 50%;
      overflow: hidden;
      img {
        height: 100%;
        width: 100%;
      }
    }

    .username {
      color: rgba(0, 0, 0, 0.85);
      font-size: 20px;
      line-height: 28px;
      font-weight: 500;
      margin-bottom: 4px;
    }
  }

  .account-center-detail {
    p {
      margin-bottom: 8px;
      padding-left: 26px;
      position: relative;
    }

    i {
      position: absolute;
      height: 14px;
      width: 14px;
      left: 0;
      top: 4px;
      background: url(https://gw.alipayobjects.com/zos/rmsportal/pBjWzVAHnOOtAUvZmZfy.svg);
    }

    .title {
      background-position: 0 0;
    }
    .group {
      background-position: 0 -22px;
    }
    .address {
      background-position: 0 -44px;
    }
  }

  .account-center-tags {
    .ant-tag {
      margin-bottom: 8px;
    }
  }

  .account-center-team {
    .members {
      a {
        display: block;
        margin: 12px 0;
        line-height: 24px;
        height: 24px;
        .member {
          font-size: 14px;
          color: rgba(0, 0, 0, 0.65);
          line-height: 24px;
          max-width: 100px;
          vertical-align: top;
          margin-left: 12px;
          transition: all 0.3s;
          display: inline-block;
        }
        &:hover {
          span {
            color: #1890ff;
          }
        }
      }
    }
  }

  .tagsTitle,
  .teamTitle {
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
    margin-bottom: 12px;
  }
}
</style>
